package com.roncoo.education.course.service.api.pc.biz;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.education.course.common.req.CourseTopicREQ;
import com.roncoo.education.course.common.req.TopicREQ;
import com.roncoo.education.course.service.dao.impl.mapper.entity.CourseTopic;
import com.roncoo.education.course.service.dao.impl.mapper.entity.Topic;
import com.roncoo.education.course.service.dao.service.impl.mapper.CourseTopicMapper;
import com.roncoo.education.course.service.dao.service.impl.mapper.TopicMapper;
import com.roncoo.education.util.base.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 试卷题目
 */
@Component
public class PcApiTopIcBiz {

    @Resource
    private TopicMapper mapper;

    /**
     * 分页返回题目 根据创建时间倒序
     * @return
     */
    public Result<Page> findPageList(TopicREQ topicREQ){
        Page<Topic> page=mapper.selectPage(new Page<Topic>(topicREQ.getPageCurrent(),topicREQ.getPageSize())
                ,new QueryWrapper<Topic>()
                        .eq("course_topic_id",topicREQ.getCourseTopicId())
                        .eq("status_id",1)
                        .orderByDesc("gmt_create"));
        return Result.success(page);
    }

    /**
     * 保存或者修改
     * @return
     */
    public Result saveOrUpdate(TopicREQ topicREQ){
        Topic topic=new Topic();
        BeanUtils.copyProperties(topicREQ,topic);
        topic.setStatusId(1);
        topic.insertOrUpdate();
        return Result.success("操作成功");

    }

    public Result del(TopicREQ topicREQ){
        Topic topic=new Topic();
        topic.setId(topicREQ.getId());
        topic.setStatusId(0);
        topic.updateById();
        return Result.success("操作成功");
    }







}
